﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace PuzzleCoop
{
    public class FloatingText : Effect
    {
        SpriteFont font;
        String text;
        int maxLifeTime = 2000;
        double lifeTime = 0;
        Vector2 velocity;
        Vector2 acceleration;
        Color color;

        public FloatingText(Game game, Vector2 pos, String text, Color color)
            : base(game, pos)
        {
            this.text = text;
            int a = new Random(DateTime.Now.Millisecond).Next(2);
            if (a == 0) a = -1;
            velocity = new Vector2(0.05f * a, -1.2f);
            acceleration = new Vector2(0.001f * a, 0.005f);
            font = game.Content.Load<SpriteFont>("Font\\SpriteFont");
            this.color = color;
        }

        public override void Update(GameTime gameTime)
        {
            lifeTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (lifeTime > maxLifeTime) Die();
            velocity += acceleration;
            position += velocity;
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font, text, position, color, 0, new Vector2(0, 0), 2, SpriteEffects.None, 0);
        }
    }
}